//    Copyright (C) Kherty.  All rights reserved.
using System.Collections.Generic;
using OpenLS.Core.Serialization;

namespace OpenLS.Chart
{
    internal class MultiLvlStrData : IOfficeXmlSerializable
    {
        internal const string xmlName = "multiLvlStrCache";
        private List<Level> _lvls = new List<Level>();
        private ExtensionList extLst;
        private int? ptCount;

        #region IOfficeXmlSerializable Members

        /// <summary>
        /// Generates an object from its XML representation
        /// </summary>
        /// <param name="context"></param>
        public void ReadXml(ReadContext context)
        {
            using (ReadContext c = context.Read(xmlName))
            {
                ptCount = c.ReadOptionalElementIntegerAttribute("ptCount"); //\\ uint
                _lvls.Clear();
                _lvls.AddRange(c.ReadOptionalWhile<Level>(Level.xmlName));
                extLst = c.ReadOptionalElement<ExtensionList>("extLst");
            }
        }

        /// <summary>
        /// Convert an object into its XML representation
        /// </summary>
        /// <param name="context"></param>
        public void WriteXml(WriteContext context)
        {
            using (var c = context.Write(xmlName))
            {
                c.WriteOptionalElementIntegerAttribute("ptCount", ptCount );
                c.WriteElements(_lvls);
                c.WriteOptionalElement(extLst );
            }
        }

        #endregion
    }
}